package cate.game.role.res.guild.po;

import cate.common.table.d.GDFunc;
import cate.common.table.d.GDGuild;
import cate.game.role.Role;
import cate.game.role.res.guild.GuildFuncBase;
import cate.game.role.res.guild.msg.rank.GuildRankResp;

import java.util.ArrayList;
import java.util.List;

public class GuildRankPO extends GuildFuncBase {


    @Override
    public int getFuncId() {
        return GDFunc.GuildFunc.RANK;
    }

    public void sendRankResp(Role role) {
        if (!guildFuncOpenCheck(role)) {
            return;
        }
        GuildRankItem myGuildData;
        int myRank;
        List<GuildRankItem> rank = new ArrayList<>();

        List<GuildPO> totalRank = role.getGame().res.guild.getRank();
        int rankSize = Math.min(totalRank.size(), GDGuild.RANK_LIMIT);
        if (rankSize == GDGuild.START_VALUE) {
            return;
        }
        for (GuildPO guild : totalRank.subList(GDGuild.START_VALUE, rankSize)) {
            rank.add(new GuildRankItem(guild.uid, guild.active.activity, guild.basic));
        }

        GuildPO myGuild = role.getRes().guild.getGuild();
        myGuildData = new GuildRankItem(myGuild.uid, myGuild.active.activity, myGuild.basic);
        myRank = role.getGame().res.guild.getSortedRankIndex(myGuild.uid);

        role.sendNow(new GuildRankResp(myGuildData, myRank, rank));
    }
}
